package problem.year2023.month04

import kotlin.math.max
import kotlin.math.min

/**
 * @author LiangMu
 * @version \$Id: Day29.java, v 0.1, 2023年05月01日 00:03 LiangMu Exp $$
 */
object Day29 {
    fun equalFrequency(word: String): Boolean {
        val chars = word.toCharArray()
        val map = HashMap<Char, Int>()
        var min = chars.size
        var max = 0
        chars.forEach {
            val value = map.getOrDefault(it, 0) + 1
            max = max(value, max)
            min = min(max,value)
            map[it] = value
        }
        return max - min == 1 || (max == 1 || min == 1)
    }
}

fun main() {
    println(Day29.equalFrequency("aacc"))
}
